﻿@using Abp.Application.Services.Dto;
@using FwProject.Restaurant.Dto
@using FwProject.Core.Restaurant
@using FwProject.Authorization
@model Tuple<LoadCarOutputDto, List<LoadingCarDto>>
@{
    ViewBag.Title = "装车单[" + Model.Item1.CreationNumber + "]";
}
@section styles{
    <link href="~/Theme/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="~/Theme/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <style type="text/css">
        .input-group[class*=col-] {
            padding: 0 15px;
        }

        .checked {
            position: absolute;
            top: 3px;
            left: 220px;
            height: 87px;
            width: 141px;
            background: url('/images/checked.gif') left top no-repeat;
            z-index: 9999;
        }
    </style>
}
<div class="row wrapper wrapper-content animated fadeInRight">
    <div class="col-sm-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>@ViewBag.Title</h5>
                <div class="ibox-tools">
                    @if (Model.Item1.ExamineStatus == ExamineStatus.未审核)
                    {
                        <button class="btn btn-primary btn-xs" data-toggle="modal" data-target="#modal_ajax" data-url="@Url.Action("UpdateTypeNumber",new { id=Model.Item1.Id})" data-backdrop="static">修改装车型号</button>
                    }

                </div>
            </div>
            <div class="ibox-content" style="height:700px">
                <div class="row m-b-sm m-t-sm">
                    <form class="form-horizontal" asp-controller="Distribution" asp-action="LoadingInvoice" data-ajax="true" data-ajax-update="#data_list" data-ajax-method="Get" data-ajax-mode="replace">
                        <input type="hidden" />
                        <div class="form-group">
                            <div class="col-md-4">
                                <label class="control-label col-md-3">单号：</label>
                                <div class="input-group">
                                    <input type="text" name="CreationNumber" class="input-sm form-control" value="@Model.Item1.CreationNumber" readonly="readonly">
                                </div>
                                @if (Model.Item1.ExamineStatus == ExamineStatus.已审核)
                                {
                                    <div class="checked" id="check_icon"></div>
                                }
                            </div>
                            <div class="col-md-4">
                                <label class="control-label col-md-3">装车时间：</label>
                                <div class="input-group">
                                    <input type="text" name="CreationTime" class="input-sm form-control" value="@Model.Item1.CreationTime.ToString("yyyy-MM-dd HH:mm:ss")" readonly="readonly">
                                </div>
                            </div>
                            <div class="col-md-4">
                                <label class="control-label col-md-3">配送司机：</label>
                                <div class="input-group">
                                    <input type="text" name="DriverName" class="input-sm form-control" value="@Model.Item1.DriverName" readonly="readonly">
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-4">
                                <label class="control-label col-md-3">车牌号：</label>
                                <div class="input-group">
                                    <input type="text" name="PlatesNumber" class="input-sm form-control" value="@Model.Item1.CarInfoModel.PlatesNumber" readonly="readonly">
                                </div>
                            </div>
                            <div class="col-md-4">
                                <label class="control-label col-md-3">装车箱数：</label>
                                <div class="input-group">
                                    <input type="text" name="Countproduct" class="input-sm form-control" value="@Model.Item1.LoadingCarInfoList.Sum(o=>o.Countproduct)" readonly="readonly">
                                </div>
                            </div>
                            <div class="col-md-4">
                                <label class="control-label col-md-3">配送状态：</label>
                                <div class="input-group">
                                    <input type="text" name="CarStatus" class="input-sm form-control" value="@Model.Item1.CarStatus" readonly="readonly">
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <div id="data_list">
                    <div>
                        <table class="table table-bordered table-hover table-rowselected">
                            <thead>
                                <tr>
                                    <th>货品型号</th>
                                    <th>装车箱数</th>    
                                    <th>装车套数</th>
                                    <th>单位</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach (var item in Model.Item2)
                                {
                                    <tr>
                                        <td>@item.TypeNumberInfoModel.Name</td>
                                        <td>@item.Countproduct</td>
                                        <td>@(item.Countproduct*item.TypeNumberInfoModel.Count)</td>
                                        <td>@item.TypeNumberInfoModel.Unit</td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </div>
                </div>
                <br />
                @if (IsGranted(PermissionNames.LoadCar_Examine) && Model.Item1.ExamineStatus == ExamineStatus.未审核)
                {

                    <div class="ibox-tools">
                        <button type="button" class="btn btn-primary btn btn-sm" id="btn" data-type="audit">确认审核</button>
                    </div>
                }
                else if(IsGranted(PermissionNames.LoadCar_AntiExamine) && Model.Item1.ExamineStatus == ExamineStatus.已审核)
                {
                    <div class="ibox-tools">
                        <button type="button" class="btn btn-primary btn btn-sm" id="btn" data-type="anti">反审核</button>
                    </div>
                }
            </div>
        </div>
    </div>
</div>
<div id="modal_ajax" class="modal inmodal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
</div>
@section scripts{
    <script src="~/Theme/js/content.min.js?v=1.0.0"></script>
    <script src="~/Theme/js/plugins/iCheck/icheck.min.js"></script>
    <script src="~/Theme/js/plugins/datapicker/bootstrap-datepicker.js"></script>
    <script src="~/Theme/js/plugins/suggest/bootstrap-suggest2014.js"></script>
    <script src="~/js/DateComm.js"></script>
    <script>
        $(document).ready(function () {
            $('#modal_ajax').on('show.bs.modal', function (e) {
                $(this).addClass('loading');
                var $button = $(e.relatedTarget);
                var url = $button.data('url');
                if (!!url) {
                    url = url + ((url.indexOf("?") > -1) ? "&r=" : "?r=") + Math.random();
                    $(this).load(url, function () {
                        $.validator.unobtrusive.parse(this); //$("#form_model_create").validate();
                        $("input[name='CarOld']").datepicker({ todayBtn: "linked", keyboardNavigation: !1, forceParse: !1, calendarWeeks: !0, autoclose: !0 });
                        $(".i-checks").iCheck({ checkboxClass: "icheckbox_square-green", radioClass: "iradio_square-green", });
                        $(this).removeClass('loading');


                        $('.btnDel').on('click', function () {
                            $(this).parent().parent().remove();
                        });

                    });
                }
            });
            $('#modal_ajax').on('hidden.bs.modal', function (e) {
                $(this).empty();
            });
        });

        $("#btn").on("click", function () {
            var type = $("#btn").data('type');
            if (type == 'audit') {
                layer.confirm('确定审核该装车单？', {
                    btn: ['确定', '取消'] //按钮
                }, function () {
                    $.post("/Distribution/EditStatus", { id: '@Model.Item1.Id', examine:'已审核' }, function (data) {
                        CommonAjaxCallback(data, function () {
                            top.Refresh();
                        }, "审核已通过！请稍等界面刷新中");
                    })
                });

            } else if (type == 'anti') {
                layer.confirm('确定反审核该装车单？', {
                    btn: ['确定', '取消'] //按钮
                }, function () {
                    $.post("/Distribution/EditStatus", { id: '@Model.Item1.Id', examine: '未审核' }, function (data) {
                        CommonAjaxCallback(data, function () {
                            top.Refresh();
                        }, "反审核成功！请稍等界面刷新中");
                    })
                });

            }
        })


        function ReloadAjaxCallbackgoback(data, successInfo) {
            CommonAjaxCallback(data, function () {
                $('#modal_ajax').modal("hide");
                window.location.reload();
            }, successInfo);
        }

    </script>
}
